package yang.cn.com.greendaoapp;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.admom.mygreendaotest.DaoMaster;
import com.admom.mygreendaotest.DaoSession;

/**
 * Created by Administrator on 2017/5/27.
 */

public class MyApplication extends Application {
    private static Context mContext;
    private static DaoSession daoSession;
    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        //greenDao全局配置,只希望有一个数据库操作对象
        //GreenDaoManager.getInstance();
        setupDatabase();
    }
    public static Context getContext() {
        return mContext;
    }
    /**
     * 配置数据库
     */
    private void setupDatabase() {
        //创建数据库shop.db"
        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "file.db", null);
        //获取可写数据库
        SQLiteDatabase db = helper.getWritableDatabase();
        //获取数据库对象
        DaoMaster daoMaster = new DaoMaster(db);
        //获取Dao对象管理者
        daoSession = daoMaster.newSession();
    }
    public static DaoSession getDaoInstant() {
        return daoSession;
    }
}
